#ifndef _DECOMP_H
#define _DECOMP_H

#include <iostream>
#include <vector>
#include <map>
#include <string>

#include "globals.h"
#include "bitops.h"
#include "Charnode.h"

using namespace std;

template <class TYPE>
class Decompressor
{
	Charnode<TYPE> *huffmanTreeRoot;
	string outputFilename;
	string compressedFilename;

	int numChars;

private:
	inline int readCount(ibstream &ibs);

public:
	Decompressor(){}
	Decompressor(string cname, string oname);

	~Decompressor();

	void decompress();
	Charnode<TYPE> * BuildHuffmanTree(vector<Charnode<TYPE> *> &chars);

	void delNode(Charnode<TYPE> *);
};


template <class TYPE>
Decompressor<TYPE>::Decompressor(string cname, string oname)
{
	outputFilename = oname;
	compressedFilename = cname;
}

template <class TYPE>
void Decompressor<TYPE>::delNode(Charnode<TYPE> * node)
{
	if(node == NULL)
		return ;
	delNode(node->GetLeft());
	delNode(node->GetRight());

	delete node;
}

template <class TYPE>
Decompressor<TYPE>::~Decompressor()
{
	LOG(__func__)
	delNode(huffmanTreeRoot);
	huffmanTreeRoot = NULL;
}